import React from "react"
import * as icons from '@ant-design/icons'
import withLoadable from '@/hoc/loadable'
export const tranformMenu=(list)=>{
    return list.map(item=>{
        //创建新的项对象
        let menuItem
        if(item.icon){
            menuItem={key:item.component,label:item.name,icon:React.createElement(icons[item.icon])}
        }else{
            menuItem={key:item.component,label:item.name}
        }
       
        if(item.childList&&item.childList.length>0){
            menuItem.children=tranformMenu(item.childList)
        }
        return menuItem
    }) 
  }

  export const transfromRoute=(list)=>{
    let ary=[]
    if(list&&list.length>0){
      list.forEach(item=>{
        if(item.childList&&item.childList.length>0){
           item.childList.forEach(subItem=>{
             const Modual=withLoadable(()=>import(`@/views${subItem.component}`))
             let routeItem={
              path:subItem.component,
              element:<Modual/>
             }
             ary.push(routeItem)
           })
        }
      })
    }
    return ary
  }